package com.vhans.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.vhans.core.domain.Management;
import com.vhans.db.service.IManagementService;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.management.ManagementDTO;
import com.vhans.db.model.vo.management.*;
import com.vhans.core.web.page.TableDataInfo;

import java.util.List;

/**
 * 管理Controller控制器
 * 
 * @author vhans
 * @date 2023-05-20
 */
@Api(tags = "管理模块")
@RestController
@RequestMapping("/dome/management")
public class ManagementController extends BaseController {
    @Autowired
    private IManagementService managementService;

    /**
     * 查询管理列表
     * @param condition 条件
     * @return {@link ManagementVO} 题目列表
     */
    @ApiOperation(value = "查询管理列表")
    @SaCheckPermission("dome:management:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<ManagementVO> list = managementService.selectManagementVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取管理详细信息
     * @param id 管理id
     * @return {@link Result<ManagementInfoVO>} 管理信息
     */
    @ApiOperation(value = "获取管理编辑信息")
    @SaCheckPermission("dome:management:query")
    @GetMapping(value = "/info/{id}")
    public Result<ManagementInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(managementService.selectManagementInfoById(id));
    }

    /**
     * 新增管理
     *
     * @param management 管理信息
     * @return {@link Result<>}
     */
    @ApiOperation(value = "新增管理")
    @SaCheckPermission("dome:management:add")
    @PostMapping("/add")
    public Result<Integer> add(@Validated @RequestBody ManagementDTO management) {
        Integer id = managementService.insertManagement(management);
        return Result.success(id);
    }

    /**
     * 修改管理
     */
    @ApiOperation(value = "修改管理")
    @SaCheckPermission("dome:management:update")
    @PutMapping("/updata")
    public Result<?> update(@Validated @RequestBody ManagementDTO management) {
        return toAjax(managementService.updateManagement(management));
    }

    /**
     * 删除管理
     *
     * @param idList 需要删除的管理主键列表
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除管理")
    @SaCheckPermission("dome:management:delete")
	@DeleteMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> idList) {
        return toAjax(managementService.deleteManagementByIdIdList(idList));
    }
}
